package com.cj.model;

import java.util.List;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;

@SuppressWarnings("serial")
public class Employee extends Model<Employee> {
	public static final Employee me = new Employee();
	
	 //根据用户名，密码登录
    public Employee login(String username, String password) {
    	String sql = "select * from employee e left join post p "
    			+ "on e.postId = p.postId left join department d "
    			+ "on p.deptId = d.deptId where empNo = ? and password = ?";
        return findFirst(sql, username, password);
    }
    
    public List<Employee> getAllEmployees() {
		String sql = "select * from employee e left join post p "
    			+ "on e.postId = p.postId left join department d "
    			+ "on p.deptId = d.deptId";
		return find(sql);
	}
    
    public Employee getEmployeeById(Integer id) {
		String sql = "select * from employee e left join post p "
    			+ "on e.postId = p.postId left join department d "
    			+ "on p.deptId = d.deptId where empId = ?";
		return findFirst(sql, id);
	}
    
    public List<Employee> getEmployeesByPost(Integer postId) {
		String sql = "select * from employee where postId = ?";
		return find(sql, postId);
	}
	
	public int getMaxID() {
		String sql = "select max(empId) from employee";
		return Db.queryInt(sql);
	}
}
